package com.ziytek.web.citizen.service;

import com.ziytek.web.citizen.constant.NumConstant;
import com.ziytek.web.citizen.mapper.BatchNoMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author fengh
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SqliteMasterService {
    private final BatchNoMapper batchNoMapper;

    private boolean isColumnExists(String columnName) {
        var columnNameStr = "%" + columnName + "%";
        long count = batchNoMapper.hasColum(columnNameStr);
        //log.info("操作表字段columnName:{}-{},count:{}", columnName, columnNameStr, count);
        return count > NumConstant.LONG_ZERO;
    }

    public void addColumnIfNotExists(String columnName) {
        if (isColumnExists(columnName)) {
            return;
        }
        batchNoMapper.addColum(columnName);
    }
}
